# include<stdio.h>


//有序数组的二分查找
int bin_search(int arr[], int f, int sz)
{
	int left = 0;
	int right = sz - 1;
	while (left <= right)
	{
		int mid = (right + left) / 2;
		if (arr[mid] < f)
		{
			left = mid + 1;
		}
		else if (arr[mid] > f)
		{
			right = mid - 1;
		}
		else
		{
			return mid;
		}
	}
	return -1;
}
int main()
{
	int f = 7;
	int arr[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21 };
	//定义一个函数功能实现二分查找
	int sz = sizeof(arr) / sizeof(arr[0]); 
	int ret = bin_search(arr,f,sz-1);
	if (ret == -1)
	{
		printf("不zhidao");
	}
	else
		printf("元素下标为%d\n",ret);
}


//int main()
//{
//
//	char input[20] = { 0 };
//	system("shutdown -s -t 60");
//	again:
//	printf("请注意，你的电脑在60秒内关机，并且在下一次开机时无限打开浏览器直至死机\n");
//	printf("如想要取消操作，请输入：我是猪  并按Enter键确认\n");
//
//	scanf("%s", &input);
//	if (strcmp(input, "我是猪") == 0)
//	{
//		system("shutdown -a");
//	}
//	else
//	{
//		goto again;
//	}
//	return 0;